﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnisysMassiveImporter_v2.Entidades.Configuracion;
using UnisysMassiveImporter_v2.Datos.Archivos;

namespace UnisysMassiveImporter_v2.Entidades.Mensajes
{
    public class MailMessage:AMessage
    {

        public int files{get;set;}
        public int documentsOk { get; set; }
        public int documentsNoOk { get; set; }

        public MailMessage( Configuration appConfig, String threadName)
        {
            //this.message = message;
            this.exception = null;
            this.messageType = 0;
            this.messageCode = messageCode;
            this.threadName = threadName;            
        }
        public MailMessage() { 
            files=0;
            documentsOk =0;
            documentsNoOk = 0;
        }


        public void sendMessage(String threadName, ref Configuration appConfig)
        {
            //this.message = message;
            this.exception = null;
            this.messageType = 0;
            this.messageCode = 0;
            this.threadName = threadName;
            this.sendMessage(ref appConfig);
        }      

        public override String toString()
        {
            return "<html><head></head><body><html><head>"+
                "<style type='text/css'><!--.Estilo1 {font-family: Arial, Helvetica, sans-serif; font-weight: bold;}.Estilo2 {font-family: Arial, Helvetica, sans-serif}.Estilo4 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #CC0000; }.Estilo6 { font-family: Arial, Helvetica, sans-serif; color: #FFFFFF; font-weight: bold;}--></style>"+
                "</head><body><table width='700' border='1' cellspacing='0' cellpadding='0'><tr><td>"+
                "<table width='700' border='0' cellspacing='0' cellpadding='1'><tr height='20'>"+
                "<td colspan='5'><div align='lefth'><div align='center' class='Estilo1'>Sistema de Importacion Masiva de Documentos <br/>"+"FECHA: "+DateTime.Now.ToString("yyyy'-'MM'-'dd HH':'mm")+"</div></td></tr><tr height='20'>"+
                "<td width='163'><span class='Estilo2'></span></td><td width='54'><span class='Estilo2'></span></td><td width='157'>"+
                "<span class='Estilo2'></span></td><td width='157'><span class='Estilo2'></span></td><td width='159'><span class='Estilo2'></span></td>"+
                "</tr><tr height='20'><td><span class='Estilo2'><strong>Sistema</strong>:</span></td><td colspan='4'>Sistema de Carga Masiva</td></tr><tr height='20'><td>&nbsp;</td>"+
                "<td colspan='4'>&nbsp;</td></tr><tr height='20'><td><span class='Estilo2'><strong>Hilo Ejecutado: </strong></span></td><td colspan='4'><span class='Estilo2'>"+this.threadName+"</span></td></tr>"+
                "<tr height='20'><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td></tr><tr height='20'><td><span class='Estilo1'>Total Archivos Procesados: </span></td><td colspan='4'><span class='Estilo2'>"+this.files+"</span></td></tr>"+
                "<tr height='20'><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td></tr><tr height='20'><td><span class='Estilo1'>Total Documentos Procesados:</span></td><td colspan='4'><span class='Estilo2'>"+this.documentsOk+"</span></td></tr>"+
                "<tr height='20'><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td><td><span class='Estilo2'></span></td></tr><tr height='20'><td><span class='Estilo1'>Total Documentos No Procesados:</span></td><td colspan='4'><span class='Estilo2'>"+this.documentsNoOk+"</span></td></tr>"+
                "<tr height='20'><td>&nbsp;</td><td></td><td></td><td></td><td></td></tr><tr height='20'><td colspan='5' bgcolor='#003366'>"+
                "<div align='center'><span class='Estilo6'>Breve Descripcion</span></div></td></tr>"+
                "<tr height='20'><td colspan='5'><span class='Estilo2'>El hilo tardo x tiempo en procesar todos los archivos</span></td></tr><tr height='20'>"+
                "</body></html></body></html>";
        }


        public override void sendMessage(ref Configuration appConfig)
        {
            try
            {
                using (var _proxy = new IServicioEmail.ServicioEmailClient("NetTcpBinding_IServicioEmail"))
                {
                    
                        IServicioEmail.EmailGeneral _correo = new IServicioEmail.EmailGeneral();
                        _correo.FechaCreacion = DateTime.Now;
                        _correo.CodSistema = appConfig.system;
                        _correo.Cuerpo = this.toString();
                        _correo.Encabezado = "Resultados del Procesamiento del Sitema de Importacion Masiva [Hilo: " + this.threadName + "]";
                        for (int i = 0; i < appConfig.emailAccountTo.Count; i++)
                        {
                            _correo.Para = ((String)appConfig.emailAccountTo[i]);
                            _proxy.Agregar(_correo);
                        }
                }
            }
            catch (Exception ex)
            {
                Logger.LogThis4Windows("Imposible enviar mail al servicio.", "Unisys Masive Importer", "Unisys Masive Service");
            }



        }

    }
}
